<?php 
class student{
    private static $num=0; //静态变量,在内存中就一份
    public function __construct(){
        student::num++;
    }
    public function destruct(){
        student::$num--;
    }
    public function show(){
        echo "总人数是:".self::$num,'<br>';
    }
}
$stu1=new student;
$stu2=new student;
$stu3=new student;
$stu2->show();   //总人数;3
unset($stu2);
$stu3->show();  //总人数:2
?>